package com.slibra.common.config;


import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.nativepay.NativePayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置 NativePayService
 */
@Configuration
public class WeChatPayConfig {


    @Autowired
    private ApplicationProperties properties ;
    @Bean
    public NativePayService nativePayService(){
        Config config =
                new RSAAutoCertificateConfig.Builder()
                        .merchantId(properties.getWechatPay().getMerchantId())
                        .privateKeyFromPath(properties.getWechatPay().getPrivateKeyPath())
                        .merchantSerialNumber(properties.getWechatPay().getMerchantSerialNumber())
                        .apiV3Key(properties.getWechatPay().getApiV3key())
                        .build();
        // 构建service
        return new NativePayService.Builder().config(config).build();
    }


}
